package xyz.robinbingo.leetcode.a20.b07.c07;

import xyz.robinbingo.leetcode.TreeNode;

public class Solution {
    public boolean hasPathSum(TreeNode root, int sum) {
        if (root == null) {
            return false;
        }
        return a(root, sum);
    }

    private boolean a(TreeNode node, int num) {
        int val = node.val;
        if (node.left == null && node.right == null) {
            return val == num;
        }
        boolean b1 = false;
        if (node.left != null) {
            b1 = a(node.left, num - val);
        }
        boolean b2 = false;
        if (node.right != null) {
            b2 = a(node.right, num - val);
        }
        return b1 || b2;
    }
}